import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-07-25
 * 21:08
 */
public class selectSort {
    public static void selectSort(int[] array){                            //选择排序
        for (int i = 0; i < array.length; i++) {
            int minindex=i;
            int j=0;
            for ( j = i+1; j < array.length; j++) {     //每次找出最小值的下标，再换到i位置
                if(array[minindex]>array[j]){
                    minindex=j;
                }
            }
            swap(array,minindex,i);
        }
    }
    public static void main(String[] args) {
        int[] array={4,656,8};
        System.out.println("排序前："+ Arrays.toString(array));
        selectSort.selectSort(array);
        System.out.println("排序后："+Arrays.toString(array));
    }
    public static void swap(int[] array,int ret1,int ret2){
        int tem=array[ret1];
        array[ret1]=array[ret2];
        array[ret2]=tem;
    }
}
